/*
 * "Copyright (c) 2007 The Regents of the University College Cork
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 *
 * IN NO EVENT SHALL THE UNIVERSITY COLLEGE CORK BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY 
 * COLLEGE CORK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE UNIVERSITY COLLEGE CORK SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY COLLEGE CORK HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 */

#ifndef TASKPRIORITY_H_
#define TASKPRIORITY_H_

  /*calculate the Number of tasks for each priority queue*/
  enum
  {
    NUM_BASIC_TASKS = uniqueCount("TinySchedulerC.TaskBasic"),
    NUM_EDF_TASKS = uniqueCount("TaskPriority<TASKEDF>"),
    NO_TASK = 255,
  };
  
  	
    /*calculates the Index of each priority at compile time. If there are no tasks for a priority queue
     * than that queue is ignored and the index of the higher queues are decremented*/
    enum{
	BASIC=(NUM_BASIC_TASKS>0)?0:NO_TASK,
	EDF=(NUM_EDF_TASKS>0)?(1-(BASIC==NO_TASK)?1:0):NO_TASK,
	NUM_PRIORITIES=(2-(((BASIC==NO_TASK)?1:0) + ((EDF==NO_TASK)?1:0))),
	HIGHER_PREEMPTIVE_INDEX=1,
	LOWER_PREEMPTIVE_INDEX=1,
  };
  
  enum{
	BASICCASE=(BASIC!=NO_TASK)?BASIC:NO_TASK,
	EDFCASE=(EDF!=NO_TASK)?EDF:NO_TASK-1,
  };
  
  
  /** context structure definition */
	typedef struct context_s {
	   /** Stack pointer */
	   uint16_t *sp;
	   /** Pointer to stack memory for de-allocating */
	   uint16_t *stack;
	   uint8_t id;
	   uint32_t deadline;
	} context_t;
	
	enum{
		BASE_CONTEXT=0,
		PREEMPTING_CONTEXT=1,
		HIGHER_PREEMPT_CONTEXT=2,
		NUM_CONTEXTS=3,
	};

#endif /*TASKPRIORITY_H_*/
